package com.ss.android.lockscreen.views.rounded;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.ColorFilter;
import android.graphics.Shader;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.support.annotation.ColorInt;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import com.ss.android.lockscreen.f;
import com.ss.android.lockscreen.views.ratio.a;
import java.util.HashSet;
import java.util.Set;

public class RoundedImageView extends a {
    private static Shader.TileMode a;
    private static final ImageView.ScaleType[] b = new ImageView.ScaleType[]{ImageView.ScaleType.MATRIX, ImageView.ScaleType.FIT_XY, ImageView.ScaleType.FIT_START, ImageView.ScaleType.FIT_CENTER, ImageView.ScaleType.FIT_END, ImageView.ScaleType.CENTER, ImageView.ScaleType.CENTER_CROP, ImageView.ScaleType.CENTER_INSIDE};
    private final float[] c;
    private Drawable d;
    private ColorStateList e;
    private float f;
    private ColorFilter g;
    private boolean h;
    private Drawable i;
    private boolean j;
    private boolean k;
    private boolean l;
    private int m;
    private int n;
    private ImageView.ScaleType o;
    private Shader.TileMode p;
    private Shader.TileMode q;
    private static boolean r = !RoundedImageView.class.desiredAssertionStatus();

    static {
        RoundedImageView.a = Shader.TileMode.CLAMP;
    }

    public RoundedImageView(Context arg3) {
        super(arg3);
        this.c = new float[]{0f, 0f, 0f, 0f};
        this.e = ColorStateList.valueOf(-16777216);
        this.f = 0f;
        this.g = null;
        this.h = false;
        this.j = false;
        this.k = false;
        this.l = false;
        this.p = RoundedImageView.a;
        this.q = RoundedImageView.a;
    }

    public RoundedImageView(Context arg2, AttributeSet arg3) {
        this(arg2, arg3, 0);
    }

    public RoundedImageView(Context arg11, AttributeSet arg12, int arg13) {
        super(arg11, arg12, arg13);
        int v9 = -2;
        int v8 = -1;
        this.c = new float[]{0f, 0f, 0f, 0f};
        this.e = ColorStateList.valueOf(-16777216);
        this.f = 0f;
        this.g = null;
        this.h = false;
        this.j = false;
        this.k = false;
        this.l = false;
        this.p = RoundedImageView.a;
        this.q = RoundedImageView.a;
        TypedArray v6 = arg11.obtainStyledAttributes(arg12, com.ss.android.lockscreen.f.e, arg13, 0);
        int v0 = v6.getInt(com.ss.android.lockscreen.f.f, v8);
        if(v0 >= 0) {
            this.setScaleType(RoundedImageView.b[v0]);
        }
        else {
            this.setScaleType(ImageView.ScaleType.FIT_CENTER);
        }

        float v3 = ((float)v6.getDimensionPixelSize(com.ss.android.lockscreen.f.i, v8));
        this.c[0] = ((float)v6.getDimensionPixelSize(com.ss.android.lockscreen.f.l, v8));
        this.c[1] = ((float)v6.getDimensionPixelSize(com.ss.android.lockscreen.f.m, v8));
        this.c[2] = ((float)v6.getDimensionPixelSize(com.ss.android.lockscreen.f.k, v8));
        this.c[3] = ((float)v6.getDimensionPixelSize(com.ss.android.lockscreen.f.j, v8));
        int v5 = 0;
        v0 = 0;
        while(v5 < 4) {
            if(this.c[v5] < 0f) {
                this.c[v5] = 0f;
            }
            else {
                v0 = 1;
            }

            ++v5;
        }

        if(v0 == 0) {
            float v0_1 = v3 < 0f ? 0f : v3;
            int v3_1;
            for(v3_1 = 0; v3_1 < 4; ++v3_1) {
                this.c[v3_1] = v0_1;
            }
        }

        this.f = ((float)v6.getDimensionPixelSize(com.ss.android.lockscreen.f.h, v8));
        if(this.f < 0f) {
            this.f = 0f;
        }

        this.e = v6.getColorStateList(com.ss.android.lockscreen.f.g);
        if(this.e == null) {
            this.e = ColorStateList.valueOf(-16777216);
        }

        this.l = v6.getBoolean(com.ss.android.lockscreen.f.n, false);
        this.k = v6.getBoolean(com.ss.android.lockscreen.f.o, false);
        v0 = v6.getInt(com.ss.android.lockscreen.f.p, v9);
        if(v0 != v9) {
            this.setTileModeX(RoundedImageView.a(v0));
            this.setTileModeY(RoundedImageView.a(v0));
        }

        v0 = v6.getInt(com.ss.android.lockscreen.f.q, v9);
        if(v0 != v9) {
            this.setTileModeX(RoundedImageView.a(v0));
        }

        v0 = v6.getInt(com.ss.android.lockscreen.f.r, v9);
        if(v0 != v9) {
            this.setTileModeY(RoundedImageView.a(v0));
        }

        this.c();
        this.a(true);
        if(this.l) {
            super.setBackgroundDrawable(this.d);
        }

        v6.recycle();
    }

    private static Shader.TileMode a(int arg1) {
        Shader.TileMode v0;
        switch(arg1) {
            case 0: {
                v0 = Shader.TileMode.CLAMP;
                break;
            }
            case 1: {
                v0 = Shader.TileMode.REPEAT;
                break;
            }
            case 2: {
                v0 = Shader.TileMode.MIRROR;
                break;
            }
            default: {
                v0 = null;
                break;
            }
        }

        return v0;
    }

    private void a(boolean arg3) {
        if(this.l) {
            if(arg3) {
                this.d = com.ss.android.lockscreen.views.rounded.a.a(this.d);
            }

            this.a(this.d, ImageView.ScaleType.FIT_XY);
        }
    }

    private Drawable a() {
        Drawable v0 = null;
        Resources v1 = this.getResources();
        if(v1 != null) {
            if(this.m != 0) {
                try {
                    v0 = v1.getDrawable(this.m);
                }
                catch(Exception v1_1) {
                    Log.w("RoundedImageView", "Unable to find resource: " + this.m, ((Throwable)v1_1));
                    this.m = 0;
                }
            }

            v0 = com.ss.android.lockscreen.views.rounded.a.a(v0);
        }

        return v0;
    }

    private void a(float arg6, float arg7, float arg8, float arg9) {
        int v4 = 3;
        int v3 = 2;
        if(this.c[0] != arg6 || this.c[1] != arg7 || this.c[v3] != arg9 || this.c[v4] != arg8) {
            this.c[0] = arg6;
            this.c[1] = arg7;
            this.c[v4] = arg8;
            this.c[v3] = arg9;
            this.c();
            this.a(false);
            this.invalidate();
        }
    }

    private void a(Drawable arg12, ImageView.ScaleType arg13) {
        int v10 = 3;
        int v9 = 2;
        int v3 = 0;
        boolean v2 = true;
        if(arg12 != null) {
            if((arg12 instanceof com.ss.android.lockscreen.views.rounded.a)) {
                Drawable v0 = arg12;
                if(arg13 == null) {
                    arg13 = ImageView.ScaleType.FIT_CENTER;
                }

                if(((com.ss.android.lockscreen.views.rounded.a)v0).j != arg13) {
                    ((com.ss.android.lockscreen.views.rounded.a)v0).j = arg13;
                    ((com.ss.android.lockscreen.views.rounded.a)v0).a();
                }

                ((com.ss.android.lockscreen.views.rounded.a)v0).h = this.f;
                ((com.ss.android.lockscreen.views.rounded.a)v0).a.setStrokeWidth(((com.ss.android.lockscreen.views.rounded.a)v0).h);
                ColorStateList v1 = this.e;
                if(v1 == null) {
                    v1 = ColorStateList.valueOf(0);
                }

                ((com.ss.android.lockscreen.views.rounded.a)v0).i = v1;
                ((com.ss.android.lockscreen.views.rounded.a)v0).a.setColor(((com.ss.android.lockscreen.views.rounded.a)v0).i.getColorForState(((com.ss.android.lockscreen.views.rounded.a)v0).getState(), -16777216));
                ((com.ss.android.lockscreen.views.rounded.a)v0).g = this.k;
                Shader.TileMode v1_1 = this.p;
                if(((com.ss.android.lockscreen.views.rounded.a)v0).b != v1_1) {
                    ((com.ss.android.lockscreen.views.rounded.a)v0).b = v1_1;
                    ((com.ss.android.lockscreen.views.rounded.a)v0).d = true;
                    ((com.ss.android.lockscreen.views.rounded.a)v0).invalidateSelf();
                }

                v1_1 = this.q;
                if(((com.ss.android.lockscreen.views.rounded.a)v0).c != v1_1) {
                    ((com.ss.android.lockscreen.views.rounded.a)v0).c = v1_1;
                    ((com.ss.android.lockscreen.views.rounded.a)v0).d = true;
                    ((com.ss.android.lockscreen.views.rounded.a)v0).invalidateSelf();
                }

                float v1_2 = this.c[0];
                float v4 = this.c[1];
                float v5 = this.c[v9];
                float v6 = this.c[v10];
                HashSet<Float> v0_1 = new HashSet(4);
                (v0_1).add(Float.valueOf(v1_2));
                (v0_1).add(Float.valueOf(v4));
                (v0_1).add(Float.valueOf(v5));
                (v0_1).add(Float.valueOf(v6));
                (v0_1).remove(Float.valueOf(0f));
                if((v0_1).size() > 1) {
                    throw new IllegalArgumentException("Multiple nonzero corner radii not yet supported.");
                }

                if(!(v0_1).isEmpty()) {
                    float v0_2 = (v0_1).iterator().next().floatValue();
                    if(!Float.isInfinite(v0_2) && !Float.isNaN(v0_2) && v0_2 >= 0f) {
                        ((com.ss.android.lockscreen.views.rounded.a)arg12).e = v0_2;
                    }else {
                        throw new IllegalArgumentException("Invalid radius value: " + v0_2);
                    }
                } else {
                    ((com.ss.android.lockscreen.views.rounded.a)arg12).e = 0f;
                }

                boolean[] v7 = ((com.ss.android.lockscreen.views.rounded.a)arg12).f;
                boolean v0_3 = v1_2 > 0f ? true : false;
                v7[0] = v0_3;
                boolean[] v1_3 = ((com.ss.android.lockscreen.views.rounded.a)arg12).f;
                v0_3 = v4 > 0f ? true : false;
                v1_3[1] = v0_3;
                v1_3 = ((com.ss.android.lockscreen.views.rounded.a)arg12).f;
                v0_3 = v5 > 0f ? true : false;
                v1_3[v9] = v0_3;
                boolean[] v0_4 = ((com.ss.android.lockscreen.views.rounded.a)arg12).f;
                if(v6 <= 0f) {
                    v2 = false;
                }

                v0_4[v10] = v2;
                this.d();
            }
            else {
                if(!(arg12 instanceof LayerDrawable)) {
                    return;
                }

                int v0_5 = ((LayerDrawable)arg12).getNumberOfLayers();
                while(v3 < v0_5) {
                    this.a(((LayerDrawable)arg12).getDrawable(v3), arg13);
                    ++v3;
                }
            }
        }
    }

    private Drawable b() {
        Drawable v0 = null;
        Resources v1 = this.getResources();
        if(v1 != null) {
            if(this.n != 0) {
                try {
                    v0 = v1.getDrawable(this.n);
                }
                catch(Exception v1_1) {
                    Log.w("RoundedImageView", "Unable to find resource: " + this.n, ((Throwable)v1_1));
                    this.n = 0;
                }
            }

            v0 = com.ss.android.lockscreen.views.rounded.a.a(v0);
        }

        return v0;
    }

    private void c() {
        this.a(this.i, this.o);
    }

    private void d() {
        if(this.i != null && (this.h)) {
            this.i = this.i.mutate();
            if(this.j) {
                this.i.setColorFilter(this.g);
            }
        }
    }

    protected void drawableStateChanged() {
        super.drawableStateChanged();
        this.invalidate();
    }

    @ColorInt public int getBorderColor() {
        return this.e.getDefaultColor();
    }

    public ColorStateList getBorderColors() {
        return this.e;
    }

    public float getBorderWidth() {
        return this.f;
    }

    public float getCornerRadius() {
        return this.getMaxCornerRadius();
    }

    public float getMaxCornerRadius() {
        float v1 = 0f;
        float[] v2 = this.c;
        int v0;
        for(v0 = 0; v0 < 4; ++v0) {
            v1 = Math.max(v2[v0], v1);
        }

        return v1;
    }

    public ImageView.ScaleType getScaleType() {
        return this.o;
    }

    public Shader.TileMode getTileModeX() {
        return this.p;
    }

    public Shader.TileMode getTileModeY() {
        return this.q;
    }

    public void setBackground(Drawable arg1) {
        this.setBackgroundDrawable(arg1);
    }

    public void setBackgroundColor(int arg2) {
        this.d = new ColorDrawable(arg2);
        this.setBackgroundDrawable(this.d);
    }

    @Deprecated public void setBackgroundDrawable(Drawable arg2) {
        this.d = arg2;
        this.a(true);
        super.setBackgroundDrawable(this.d);
    }

    public void setBackgroundResource(@DrawableRes int arg2) {
        if(this.n != arg2) {
            this.n = arg2;
            this.d = this.b();
            this.setBackgroundDrawable(this.d);
        }
    }

    public void setBorderColor(@ColorInt int arg2) {
        this.setBorderColor(ColorStateList.valueOf(arg2));
    }

    public void setBorderColor(ColorStateList arg3) {
        if(!this.e.equals(arg3)) {
            if(arg3 == null) {
                arg3 = ColorStateList.valueOf(-16777216);
            }

            this.e = arg3;
            this.c();
            this.a(false);
            if(this.f <= 0f) {
                return;
            }

            this.invalidate();
        }
    }

    public void setBorderWidth(float arg2) {
        if(this.f != arg2) {
            this.f = arg2;
            this.c();
            this.a(false);
            this.invalidate();
        }
    }

    public void setBorderWidth(@DimenRes int arg2) {
        this.setBorderWidth(this.getResources().getDimension(arg2));
    }

    public void setColorFilter(ColorFilter arg3) {
        if(this.g != arg3) {
            this.g = arg3;
            this.j = true;
            this.h = true;
            this.d();
            this.invalidate();
        }
    }

    public void setCornerRadius(float arg1) {
        this.a(arg1, arg1, arg1, arg1);
    }

    public void setCornerRadiusDimen(@DimenRes int arg2) {
        float v0 = this.getResources().getDimension(arg2);
        this.a(v0, v0, v0, v0);
    }

    public void setImageBitmap(Bitmap arg2) {
        this.m = 0;
        this.i = com.ss.android.lockscreen.views.rounded.a.a(arg2);
        this.c();
        super.setImageDrawable(this.i);
    }

    public void setImageDrawable(Drawable arg2) {
        this.m = 0;
        this.i = com.ss.android.lockscreen.views.rounded.a.a(arg2);
        this.c();
        super.setImageDrawable(this.i);
    }

    public void setImageResource(@DrawableRes int arg2) {
        if(this.m != arg2) {
            this.m = arg2;
            this.i = this.a();
            this.c();
            super.setImageDrawable(this.i);
        }
    }

    public void setImageURI(Uri arg2) {
        super.setImageURI(arg2);
        this.setImageDrawable(this.getDrawable());
    }

    public void setOval(boolean arg2) {
        this.k = arg2;
        this.c();
        this.a(false);
        this.invalidate();
    }

    public void setScaleType(ImageView.ScaleType arg3) {
        if(!RoundedImageView.r && arg3 == null) {
            throw new AssertionError();
        }

        if(this.o != arg3) {
            this.o = arg3;
            switch(com.ss.android.lockscreen.views.rounded.c.a[arg3.ordinal()]) {
                case 1: 
                case 2: 
                case 3: 
                case 4: 
                case 5: 
                case 6: 
                case 7: {
                    super.setScaleType(ImageView.ScaleType.FIT_XY);
                    break;
                }
                default: {
                    super.setScaleType(arg3);
                    break;
                }
            }

            this.c();
            this.a(false);
            this.invalidate();
        }
    }

    public void setTileModeX(Shader.TileMode arg2) {
        if(this.p != arg2) {
            this.p = arg2;
            this.c();
            this.a(false);
            this.invalidate();
        }
    }

    public void setTileModeY(Shader.TileMode arg2) {
        if(this.q != arg2) {
            this.q = arg2;
            this.c();
            this.a(false);
            this.invalidate();
        }
    }
}

